package trunk.res;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
public class CPU8086 extends JFrame implements ItemListener,ActionListener{
	public int choice;
	int begin=0;
	int status=-1;
	int next_step=0;
	JPanel p=new JPanel();
	JButton start=new JButton("开始");
	JButton stop=new JButton("停止");
	JButton next=new JButton("下一步");
	Choice zhiling1=new Choice();
	Choice zhiling2=new Choice();
	Choice xuanzhi1=new Choice();
	Choice xuanzhi2=new Choice();
	JTextField d=new JTextField("                " +
                                "                ");
	void init(){
		setLayout(null);
		start.addActionListener(this);
		stop.addActionListener(this);
		next.addActionListener(this);
		p.add(start);
		p.add(stop);
		p.add(next);
		add(p);
		p.setBounds(720, 220, 250, 40);
		//第一个选择指令
		zhiling1.addItem("");
		zhiling1.addItem("MOV11");
		zhiling1.addItem("双操作数指令");
		zhiling1.addItem("单操作数指令");
		zhiling1.addItem("移交指令、返回指令");
		zhiling1.addItem("跳转指令");
		zhiling1.addItemListener(this);
		add(zhiling1);
		//第二个选择指令
		zhiling1.setBounds(780, 20, 150,20);
		add(zhiling2);
		zhiling2.setBounds(780, 50, 150,20);	
		zhiling2.addItemListener(this);
		//选择源操作数选址方式
		xuanzhi1.setBounds(860, 80, 100,20);
		add(xuanzhi1);
		xuanzhi1.addItemListener(this);
		add(xuanzhi2);
		xuanzhi2.setBounds(860, 110, 100,20);
		xuanzhi2.addItemListener(this);	
		//打印完整指令对话框		
		add(d);	
		d.setBounds(720, 170, 200,40);
	}
	
	void mov(){
		zhiling2.addItem("");
		zhiling2.addItem("MOV");	
		add(zhiling2);
		zhiling2.setBounds(780, 50, 170,20);
		yuan();
		mudi();
		
	}
	void shuang(){
		zhiling2.addItem("");
		zhiling2.addItem("ADD");
		zhiling2.addItem("SUB");
		zhiling2.addItem("AND");
		zhiling2.addItem("OR");
		zhiling2.addItem("EOR");
		add(zhiling2);
		zhiling2.setBounds(780, 50, 150,20);
		yuan();
		mudi();
	}
	void dan(){
		zhiling2.addItem("");
		zhiling2.addItem("COM");
		zhiling2.addItem("NEG");
		zhiling2.addItem("INC");
		zhiling2.addItem("DEC");
		zhiling2.addItem("SL");
		zhiling2.addItem("SR");
		add(zhiling2);
		zhiling2.setBounds(780, 50, 150,20);
		yuan();
	}
	void yi(){
		zhiling2.addItem("");
		zhiling2.addItem("JMP");
		zhiling2.addItem("RST");
		add(zhiling2);
		zhiling2.setBounds(780, 50, 150,20);
		yuan_1();
	}
	void tiao(){
		zhiling2.addItem("");
		zhiling2.addItem("JSR");
		add(zhiling2);
		zhiling2.setBounds(780, 50, 150,20);
		yuan_2();
	}
	void yuan(){
		xuanzhi1.addItem("");
		xuanzhi1.addItem("R0");
		xuanzhi1.addItem("(R0)");
		xuanzhi1.addItem("-(R0)");
		xuanzhi1.addItem("(R0)+");
		xuanzhi1.addItem("@(R0)+");
		xuanzhi1.addItem("X(R0)");
		xuanzhi1.setBounds(860, 80, 100,20);
		add(xuanzhi1);
	}
	void yuan_1(){
		xuanzhi1.addItem("");		
		xuanzhi1.addItem("R0");
		xuanzhi1.addItem("(R0)");
		xuanzhi1.addItem("(R0)+");
		xuanzhi1.addItem("非PC");
		xuanzhi1.addItem("PC");
		xuanzhi1.addItem("SKP");
		xuanzhi1.addItem("X(PC)");
		xuanzhi1.setBounds(860, 80, 100,20);
		add(xuanzhi1);
	}
	void yuan_2(){
		xuanzhi1.addItem("");		
		xuanzhi1.addItem("R0");
		xuanzhi1.addItem("(R0)");
		xuanzhi1.addItem("(R0)+");
		xuanzhi1.addItem("非PC");
		xuanzhi1.addItem("PC");
		xuanzhi1.setBounds(860, 80, 100,20);
		add(xuanzhi1);
	}
	void mudi(){
		xuanzhi2.addItem("");
		xuanzhi2.addItem("R1");
		xuanzhi2.addItem("(R1)");
		xuanzhi2.addItem("-(R1)");
		xuanzhi2.addItem("(R1)+");
		xuanzhi2.addItem("@(R1)+");
		xuanzhi2.addItem("X(R1)");
		add(xuanzhi2);
		xuanzhi2.setBounds(860, 110, 100,20);
	}
	
	public CPU8086(){
		super("HEHE");
		setSize(WIDTH/9*10,HEIGHT/9*10);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setVisible(true);
		
	}
/**
	 * 
	 */
	
	
	public void itemStateChanged(ItemEvent e) {
		// TODO Auto-generated method stub
		String arg=(String)e.getItem();
		if(arg.equals("MOV11")){
			choice = 1000;begin=1;
		}
		else if(arg.equals("双操作数指令")){
			choice = 2000;begin=1;
		}
		else if(arg.equals("单操作数指令")){
			choice = 3000;begin=1;
		}
		else if(arg.equals("移交指令、返回指令")){
			choice = 4000;begin=1;
		}
		else if(arg.equals("跳转指令")){
			choice = 5000;begin=1;
		}
		else if(arg.equals("MOV")){
			choice = 1100;
		}
		else if(arg.equals("ADD")){
			choice = 2100;
		}
		else if(arg.equals("SUB")){
			choice = 2200;
		}
		else if(arg.equals("AND")){
			choice = 2300;
		}
		else if(arg.equals("OR")){
			choice = 2400;
		}		
		else if(arg.equals("EOR")){
			choice = 2500;
		}
		else if(arg.equals("COM")){
			choice = 3100;
		}
		else if(arg.equals("NEG")){
			choice = 3200;
		}
		else if(arg.equals("INC")){
			choice = 3300;
		}
		else if(arg.equals("DEC")){
			choice = 3400;
		}
		else if(arg.equals("SL")){
			choice = 3400;
		}
		else if(arg.equals("SR")){
			choice = 3400;
		}
		else if(arg.equals("JMP")){
			choice = 4100;
		}
		else if(arg.equals("RST")){
			choice = 4200;
		}
		else if(arg.equals("JSR")){
			choice = 5100;
		}
		else if(arg.equals("R0")){
			int i,j;
			i=choice%10;
			j=choice%100;
			choice=choice-j+i;
			choice += 10;
		}
		else if(arg.equals("(R0)")){
			int i,j;
			i=choice%10;
			j=choice%100;
			choice=choice-j+i;
			choice += 20;
		}
		else if(arg.equals("-(R0)")){
			int i,j;
			i=choice%10;
			j=choice%100;
			choice=choice-j+i;
			choice += 30;
		}
		else if(arg.equals("(R0)+")){
			int i,j;
			i=choice%10;
			j=choice%100;
			choice=choice-j+i;
			choice += 40;
		}
		else if(arg.equals("@(R0)+")){
			int i,j;
			i=choice%10;
			j=choice%100;
			choice=choice-j+i;
			choice += 50;
		}
		else if(arg.equals("X(R0)")){
			int i,j;
			i=choice%10;
			j=choice%100;
			choice=choice-j+i;
			choice += 60;
		}
		else if(arg.equals("非PC")){
			int i,j;
			i=choice%10;
			j=choice%100;
			choice=choice-j+i;
			choice += 50;
		}
		else if(arg.equals("PC")){
			int i,j;
			i=choice%10;
			j=choice%100;
			choice=choice-j+i;
			choice += 60;
		}
		else if(arg.equals("SKP")){
			int i,j;
			i=choice%10;
			j=choice%100;
			choice=choice-j+i;
			choice += 70;
		}
		else if(arg.equals("X(PC)")){
			int i,j;
			i=choice%10;
			j=choice%100;
			choice=choice-j+i;
			choice += 80;
		}
		else if(arg.equals("R1")){
			int i;
			i=choice%10;
			choice-=i;
			choice += 1;
		}
		else if(arg.equals("(R1)")){
			int i;
			i=choice%10;
			choice-=i;
			choice += 2;
		}
		else if(arg.equals("-(R1)")){
			int i;
			i=choice%10;
			choice-=i;
			choice += 3;
		}
		else if(arg.equals("(R1)+")){
			int i;
			i=choice%10;
			choice-=i;
			choice += 4;
		}
		else if(arg.equals("@(R1)+")){
			int i;
			i=choice%10;
			choice-=i;
			choice += 5;
		}
		else if(arg.equals("X(R1)")){
			int i;
			i=choice%10;
			choice-=i;
			choice += 6;
		}
	}
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		if(e.getSource()==start){
			status=0;
			next_step=1;
			repaint();
		}
		if(e.getSource()==stop){
			status=-1;
			repaint();
		}
		if(e.getSource()==next){
			status=0;
			next_step++;
			repaint();
		}
	}
	
	
	
private static final long serialVersionUID = 1L;
//定义屏幕大小
final int WIDTH=900,HEIGHT=650; 
final float lineWidth=3.0f;
//运用双缓存进行绘图
private Image Ibuffer;
private Graphics Gbuffer;
public void paint(Graphics g){
	if(begin==0){
		init();
		begin++;
	}
	
	if(begin==1){
		
		zhiling2.removeAll();
		xuanzhi1.removeAll();
		xuanzhi2.removeAll();
		switch(choice){
		case 1000:mov();begin++;break;
		case 2000:shuang();begin++;break;
		case 3000:dan();begin++;break;
		case 4000:yi();begin++;break;
		case 5000:tiao();begin++;break;
		}		
	}
	
	
	
	if(choice==1111) d.setText("MOV RO,R1");
	if(choice==1112) d.setText("MOV RO,(R1)");
	if(choice==1113) d.setText("MOV RO,-(R1)");
	if(choice==1114) d.setText("MOV RO,(R1)+");
	if(choice==1115) d.setText("MOV RO,@(R1)+");
	if(choice==1116) d.setText("MOV RO,X(R1)");
	
	if(choice==1121) d.setText("MOV (RO),R1");
	if(choice==1122) d.setText("MOV (RO),(R1)");
	if(choice==1123) d.setText("MOV (RO),-(R1)");
	if(choice==1124) d.setText("MOV (RO),(R1)+");
	if(choice==1125) d.setText("MOV (RO),@(R1)+");
	if(choice==1126) d.setText("MOV (RO),X(R1)");
	
	if(choice==1131) d.setText("MOV -(RO),R1");
	if(choice==1132) d.setText("MOV -(RO),(R1)");
	if(choice==1133) d.setText("MOV -(RO),-(R1)");
	if(choice==1134) d.setText("MOV -(RO),(R1)+");
	if(choice==1135) d.setText("MOV -(RO),@(R1)+");
	if(choice==1136) d.setText("MOV -(RO),X(R1)");
	
	if(choice==1141) d.setText("MOV (RO)+,R1");
	if(choice==1142) d.setText("MOV (RO)+,(R1)");
	if(choice==1143) d.setText("MOV (RO)+,-(R1)");
	if(choice==1144) d.setText("MOV (RO)+,(R1)+");
	if(choice==1145) d.setText("MOV (RO)+,@(R1)+");
	if(choice==1146) d.setText("MOV (RO)+,X(R1)");
	
	if(choice==1151) d.setText("MOV @(RO)+,R1");
	if(choice==1152) d.setText("MOV @(RO)+,(R1)");
	if(choice==1153) d.setText("MOV @(RO)+,-(R1)");
	if(choice==1154) d.setText("MOV @(RO)+,(R1)+");
	if(choice==1155) d.setText("MOV @(RO)+,@(R1)+");
	if(choice==1156) d.setText("MOV @(RO)+,X(R1)");
	
	if(choice==1161) d.setText("MOV X(RO),R1");
	if(choice==1162) d.setText("MOV X(RO),(R1)");
	if(choice==1163) d.setText("MOV X(RO),-(R1)");
	if(choice==1164) d.setText("MOV X(RO),(R1)+");
	if(choice==1165) d.setText("MOV X(RO),@(R1)+");
	if(choice==1166) d.setText("MOV X(RO),X(R1)");
	
	if(choice==2111) d.setText("ADD RO,R1");
	if(choice==2112) d.setText("ADD RO,(R1)");
	if(choice==2113) d.setText("ADD RO,-(R1)");
	if(choice==2114) d.setText("ADD RO,(R1)+");
	if(choice==2115) d.setText("ADD RO,@(R1)+");
	if(choice==2116) d.setText("ADD RO,X(R1)");
	
	if(choice==2121) d.setText("ADD (RO),R1");
	if(choice==2122) d.setText("ADD (RO),(R1)");
	if(choice==2123) d.setText("ADD (RO),-(R1)");
	if(choice==2124) d.setText("ADD (RO),(R1)+");
	if(choice==2125) d.setText("ADD (RO),@(R1)+");
	if(choice==2126) d.setText("ADD (RO),X(R1)");
	
	if(choice==2131) d.setText("ADD -(RO),R1");
	if(choice==2132) d.setText("ADD -(RO),(R1)");
	if(choice==2133) d.setText("ADD -(RO),-(R1)");
	if(choice==2134) d.setText("ADD -(RO),(R1)+");
	if(choice==2135) d.setText("ADD -(RO),@(R1)+");
	if(choice==2136) d.setText("ADD -(RO),X(R1)");
	
	if(choice==2141) d.setText("ADD (RO)+,R1");
	if(choice==2142) d.setText("ADD (RO)+,(R1)");
	if(choice==2143) d.setText("ADD (RO)+,-(R1)");
	if(choice==2144) d.setText("ADD (RO)+,(R1)+");
	if(choice==2145) d.setText("ADD (RO)+,@(R1)+");
	if(choice==2146) d.setText("ADD (RO)+,X(R1)");
	
	if(choice==2151) d.setText("ADD @(RO)+,R1");
	if(choice==2152) d.setText("ADD @(RO)+,(R1)");
	if(choice==2153) d.setText("ADD @(RO)+,-(R1)");
	if(choice==2154) d.setText("ADD @(RO)+,(R1)+");
	if(choice==2155) d.setText("ADD @(RO)+,@(R1)+");
	if(choice==2156) d.setText("ADD @(RO)+,X(R1)");
	
	if(choice==2161) d.setText("ADD X(RO),R1");
	if(choice==2162) d.setText("ADD X(RO),(R1)");
	if(choice==2163) d.setText("ADD X(RO),-(R1)");
	if(choice==2164) d.setText("ADD X(RO),(R1)+");
	if(choice==2165) d.setText("ADD X(RO),@(R1)+");
	if(choice==2166) d.setText("ADD X(RO),X(R1)");
	
	
	if(choice==2211) d.setText("SUB RO,R1");
	if(choice==2212) d.setText("SUB RO,(R1)");
	if(choice==2213) d.setText("SUB RO,-(R1)");
	if(choice==2214) d.setText("SUB RO,(R1)+");
	if(choice==2215) d.setText("SUB RO,@(R1)+");
	if(choice==2216) d.setText("SUB RO,X(R1)");
	
	if(choice==2221) d.setText("SUB (RO),R1");
	if(choice==2222) d.setText("SUB (RO),(R1)");
	if(choice==2223) d.setText("SUB (RO),-(R1)");
	if(choice==2224) d.setText("SUB (RO),(R1)+");
	if(choice==2225) d.setText("SUB (RO),@(R1)+");
	if(choice==2226) d.setText("SUB (RO),X(R1)");
	
	if(choice==2231) d.setText("SUB -(RO),R1");
	if(choice==2232) d.setText("SUB -(RO),(R1)");
	if(choice==2233) d.setText("SUB -(RO),-(R1)");
	if(choice==2234) d.setText("SUB -(RO),(R1)+");
	if(choice==2235) d.setText("SUB -(RO),@(R1)+");
	if(choice==2236) d.setText("SUB -(RO),X(R1)");
	
	if(choice==2241) d.setText("SUB (RO)+,R1");
	if(choice==2242) d.setText("SUB (RO)+,(R1)");
	if(choice==2243) d.setText("SUB (RO)+,-(R1)");
	if(choice==2244) d.setText("SUB (RO)+,(R1)+");
	if(choice==2245) d.setText("SUB (RO)+,@(R1)+");
	if(choice==2246) d.setText("SUB (RO)+,X(R1)");
	
	if(choice==2251) d.setText("SUB @(RO)+,R1");
	if(choice==2252) d.setText("SUB @(RO)+,(R1)");
	if(choice==2253) d.setText("SUB @(RO)+,-(R1)");
	if(choice==2254) d.setText("SUB @(RO)+,(R1)+");
	if(choice==2255) d.setText("SUB @(RO)+,@(R1)+");
	if(choice==2256) d.setText("SUB @(RO)+,X(R1)");
	
	if(choice==2261) d.setText("SUB X(RO),R1");
	if(choice==2262) d.setText("SUB X(RO),(R1)");
	if(choice==2263) d.setText("SUB X(RO),-(R1)");
	if(choice==2264) d.setText("SUB X(RO),(R1)+");
	if(choice==2265) d.setText("SUB X(RO),@(R1)+");
	if(choice==2266) d.setText("SUB X(RO),X(R1)");
	
	
	if(choice==2311) d.setText("AND RO,R1");
	if(choice==2312) d.setText("AND RO,(R1)");
	if(choice==2313) d.setText("AND RO,-(R1)");
	if(choice==2314) d.setText("AND RO,(R1)+");
	if(choice==2315) d.setText("AND RO,@(R1)+");
	if(choice==2316) d.setText("AND RO,X(R1)");
	
	if(choice==2321) d.setText("AND (RO),R1");
	if(choice==2322) d.setText("AND (RO),(R1)");
	if(choice==2323) d.setText("AND (RO),-(R1)");
	if(choice==2324) d.setText("AND (RO),(R1)+");
	if(choice==2325) d.setText("AND (RO),@(R1)+");
	if(choice==2326) d.setText("AND (RO),X(R1)");
	
	if(choice==2331) d.setText("AND -(RO),R1");
	if(choice==2332) d.setText("AND -(RO),(R1)");
	if(choice==2333) d.setText("AND -(RO),-(R1)");
	if(choice==2334) d.setText("AND -(RO),(R1)+");
	if(choice==2335) d.setText("AND -(RO),@(R1)+");
	if(choice==2336) d.setText("AND -(RO),X(R1)");
	
	if(choice==2341) d.setText("AND (RO)+,R1");
	if(choice==2342) d.setText("AND (RO)+,(R1)");
	if(choice==2343) d.setText("AND (RO)+,-(R1)");
	if(choice==2344) d.setText("AND (RO)+,(R1)+");
	if(choice==2345) d.setText("AND (RO)+,@(R1)+");
	if(choice==2346) d.setText("AND (RO)+,X(R1)");
	
	if(choice==2351) d.setText("AND @(RO)+,R1");
	if(choice==2352) d.setText("AND @(RO)+,(R1)");
	if(choice==2353) d.setText("AND @(RO)+,-(R1)");
	if(choice==2354) d.setText("AND @(RO)+,(R1)+");
	if(choice==2355) d.setText("AND @(RO)+,@(R1)+");
	if(choice==2356) d.setText("AND @(RO)+,X(R1)");
	
	if(choice==2361) d.setText("AND X(RO),R1");
	if(choice==2362) d.setText("AND X(RO),(R1)");
	if(choice==2363) d.setText("AND X(RO),-(R1)");
	if(choice==2364) d.setText("AND X(RO),(R1)+");
	if(choice==2365) d.setText("AND X(RO),@(R1)+");
	if(choice==2366) d.setText("AND X(RO),X(R1)");
	
	
	if(choice==2411) d.setText("OR RO,R1");
	if(choice==2412) d.setText("OR RO,(R1)");
	if(choice==2413) d.setText("OR RO,-(R1)");
	if(choice==2414) d.setText("OR RO,(R1)+");
	if(choice==2415) d.setText("OR RO,@(R1)+");
	if(choice==2416) d.setText("OR RO,X(R1)");
	
	if(choice==2421) d.setText("OR (RO),R1");
	if(choice==2422) d.setText("OR (RO),(R1)");
	if(choice==2423) d.setText("OR (RO),-(R1)");
	if(choice==2424) d.setText("OR (RO),(R1)+");
	if(choice==2425) d.setText("OR (RO),@(R1)+");
	if(choice==2426) d.setText("OR (RO),X(R1)");
	
	if(choice==2431) d.setText("OR -(RO),R1");
	if(choice==2432) d.setText("OR -(RO),(R1)");
	if(choice==2433) d.setText("OR -(RO),-(R1)");
	if(choice==2434) d.setText("OR -(RO),(R1)+");
	if(choice==2435) d.setText("OR -(RO),@(R1)+");
	if(choice==2436) d.setText("OR-(RO),X(R1)");
	
	if(choice==2441) d.setText("OR (RO)+,R1");
	if(choice==2442) d.setText("OR (RO)+,(R1)");
	if(choice==2443) d.setText("OR (RO)+,-(R1)");
	if(choice==2444) d.setText("OR (RO)+,(R1)+");
	if(choice==2445) d.setText("OR (RO)+,@(R1)+");
	if(choice==2346) d.setText("OR (RO)+,X(R1)");
	
	if(choice==2451) d.setText("OR @(RO)+,R1");
	if(choice==2452) d.setText("OR @(RO)+,(R1)");
	if(choice==2453) d.setText("OR @(RO)+,-(R1)");
	if(choice==2454) d.setText("OR @(RO)+,(R1)+");
	if(choice==2455) d.setText("OR @(RO)+,@(R1)+");
	if(choice==2456) d.setText("OR @(RO)+,X(R1)");
	
	if(choice==2461) d.setText("OR X(RO),R1");
	if(choice==2462) d.setText("OR X(RO),(R1)");
	if(choice==2463) d.setText("OR X(RO),-(R1)");
	if(choice==2464) d.setText("OR X(RO),(R1)+");
	if(choice==2465) d.setText("OR X(RO),@(R1)+");
	if(choice==2466) d.setText("OR X(RO),X(R1)");
	
	
	if(choice==2511) d.setText("EOR RO,R1");
	if(choice==2512) d.setText("EOR RO,(R1)");
	if(choice==2513) d.setText("EOR RO,-(R1)");
	if(choice==2514) d.setText("EOR RO,(R1)+");
	if(choice==2515) d.setText("EOR RO,@(R1)+");
	if(choice==2516) d.setText("EOR RO,X(R1)");
	
	if(choice==2521) d.setText("EOR (RO),R1");
	if(choice==2522) d.setText("EOR (RO),(R1)");
	if(choice==2523) d.setText("EOR (RO),-(R1)");
	if(choice==2524) d.setText("EOR (RO),(R1)+");
	if(choice==2525) d.setText("EOR (RO),@(R1)+");
	if(choice==2526) d.setText("EOR (RO),X(R1)");
	
	if(choice==2531) d.setText("EOR -(RO),R1");
	if(choice==2532) d.setText("EOR -(RO),(R1)");
	if(choice==2533) d.setText("EOR -(RO),-(R1)");
	if(choice==2534) d.setText("EOR -(RO),(R1)+");
	if(choice==2535) d.setText("EOR -(RO),@(R1)+");
	if(choice==2536) d.setText("EOR-(RO),X(R1)");
	
	if(choice==2541) d.setText("EOR (RO)+,R1");
	if(choice==2542) d.setText("EOR (RO)+,(R1)");
	if(choice==2543) d.setText("EOR (RO)+,-(R1)");
	if(choice==2544) d.setText("EOR (RO)+,(R1)+");
	if(choice==2545) d.setText("EOR (RO)+,@(R1)+");
	if(choice==2546) d.setText("EOR (RO)+,X(R1)");
	
	if(choice==2551) d.setText("EOR @(RO)+,R1");
	if(choice==2552) d.setText("EOR @(RO)+,(R1)");
	if(choice==2553) d.setText("EOR @(RO)+,-(R1)");
	if(choice==2554) d.setText("EOR @(RO)+,(R1)+");
	if(choice==2555) d.setText("EOR @(RO)+,@(R1)+");
	if(choice==2556) d.setText("EOR @(RO)+,X(R1)");
	
	if(choice==2561) d.setText("EOR X(RO),R1");
	if(choice==2562) d.setText("EOR X(RO),(R1)");
	if(choice==2563) d.setText("EOR X(RO),-(R1)");
	if(choice==2564) d.setText("EOR X(RO),(R1)+");
	if(choice==2565) d.setText("EOR X(RO),@(R1)+");
	if(choice==2566) d.setText("EOR X(RO),X(R1)");
	
	
	if(choice==3110) d.setText("CMP RO");
	if(choice==3120) d.setText("CMP (R0)");
	if(choice==3130) d.setText("CMP -(R0)");
	if(choice==3140) d.setText("CMP (R0)+");
	if(choice==3150) d.setText("CMP @(R0)+");
	if(choice==3160) d.setText("CMP X(R0)");
	
	if(choice==3210) d.setText("NEG RO");
	if(choice==3220) d.setText("NEG (R0)");
	if(choice==3230) d.setText("NEG -(R0)");
	if(choice==3240) d.setText("NEG (R0)+");
	if(choice==3250) d.setText("NEG @(R0)+");
	if(choice==3260) d.setText("NEG X(R0)");
	
	if(choice==3310) d.setText("INC RO");
	if(choice==3320) d.setText("INC (R0)");
	if(choice==3330) d.setText("INC -(R0)");
	if(choice==3340) d.setText("INC (R0)+");
	if(choice==3350) d.setText("INC @(R0)+");
	if(choice==3360) d.setText("INC X(R0)");
	
	if(choice==3410) d.setText("DEC RO");
	if(choice==3420) d.setText("DEC (R0)");
	if(choice==3430) d.setText("DEC -(R0)");
	if(choice==3440) d.setText("DEC (R0)+");
	if(choice==3450) d.setText("DEC @(R0)+");
	if(choice==3460) d.setText("DEC X(R0)");
	
	if(choice==3510) d.setText("SL RO");
	if(choice==3520) d.setText("SL (R0)");
	if(choice==3530) d.setText("SL -(R0)");
	if(choice==3540) d.setText("SL (R0)+");
	if(choice==3550) d.setText("SL @(R0)+");
	if(choice==3560) d.setText("SL X(R0)");
	
	if(choice==3610) d.setText("SR RO");
	if(choice==3620) d.setText("SR (R0)");
	if(choice==3630) d.setText("SR -(R0)");
	if(choice==3640) d.setText("SR (R0)+");
	if(choice==3650) d.setText("SR @(R0)+");
	if(choice==3660) d.setText("SR X(R0)");
	
		
	if(choice==4110) d.setText("JMP R0");
	if(choice==4120) d.setText("JMP (R0)");
	if(choice==4140) d.setText("JMP (R0)+");
	if(choice==4150) d.setText("JMP 非PC");
	if(choice==4160) d.setText("JMP PC");
	if(choice==4170) d.setText("JMP SKP");
	if(choice==4180) d.setText("JMP X(PC)");
	
	if(choice==4110) d.setText("JMP R0");
	if(choice==4120) d.setText("JMP (R0)");
	if(choice==4140) d.setText("JMP (R0)+");
	if(choice==4150) d.setText("JMP 非PC");
	if(choice==4160) d.setText("JMP PC");
	if(choice==4170) d.setText("JMP SKP");
	if(choice==4180) d.setText("JMP X(PC)");
	
	if(choice==4210) d.setText("RST R0");
	if(choice==4220) d.setText("RST (R0)");
	if(choice==4240) d.setText("RST (R0)+");
	if(choice==4250) d.setText("RST 非PC");
	if(choice==4260) d.setText("RST PC");
	if(choice==4270) d.setText("RST SKP");
	if(choice==4280) d.setText("RST X(PC)");
	
	
	if(choice==5110) d.setText("JSR R0");
	if(choice==5120) d.setText("JSR (R0)");
	if(choice==5140) d.setText("JSR (R0)+");
	if(choice==5150) d.setText("JSR 非PC");
	if(choice==5160) d.setText("JSR PC");
	
	if(Ibuffer==null){
		Ibuffer=createImage(WIDTH, HEIGHT);
		Gbuffer=Ibuffer.getGraphics();
	}
	((Graphics2D)Gbuffer).setStroke(new BasicStroke(lineWidth));
	Gbuffer.setColor(Color.black);
	;
	//绘出地址总线
	Gbuffer.drawLine(20,100,650,100);
	//绘出数据总线
	Gbuffer.drawLine(20,120,650,120);
	//绘出控制总线
	Gbuffer.drawLine(20, 140, 650, 140);
	//绘制移位器
	Gbuffer.fillRect(90,200,80,30);
	//绘制ALU
	Gbuffer.drawLine(130, 230, 130, 280);
	int xPoint[]={90,170,210,135,130,125,50,90};
	int yPoint[]={280,280,340,340,330,340,340,280};
	Gbuffer.drawPolyline(xPoint,yPoint,8);
	Gbuffer.fillRect(100,290,60,30);
	//选择器A、B
	Gbuffer.fillRect(50,390,75,30);
	Gbuffer.fillRect(135,390,75,30);
	Gbuffer.drawLine(87, 340, 87, 390);
	Gbuffer.drawLine(172, 340, 172, 390);
	Gbuffer.drawLine(60, 420, 60, 450);
	Gbuffer.drawLine(115, 420, 115, 450);
	Gbuffer.drawLine(145, 420, 145, 450);
	Gbuffer.drawLine(200, 420, 200, 450);
	//内总线
	int xPoint1[]={130,130,350,350};
	int yPoint1[]={200,180,180,600};
	Gbuffer.drawPolyline(xPoint1,yPoint1,4);
	//绘制R0、MAR、R1、MDR、R2、IR、R3、PC、C、SP、D、PSW，按顺序绘制
	Gbuffer.fillRect(280,200,50,30);
	Gbuffer.fillRect(370,200,50,30);
	Gbuffer.fillRect(280,270,50,30);
	Gbuffer.fillRect(370,270,50,30);
	Gbuffer.fillRect(280,340,50,30);
	Gbuffer.fillRect(370,340,50,30);
	Gbuffer.fillRect(280,410,50,30);
	Gbuffer.fillRect(370,410,50,30);
	Gbuffer.fillRect(280,480,50,30);
	Gbuffer.fillRect(370,480,50,30);
	Gbuffer.fillRect(280,550,50,30);
	Gbuffer.fillRect(370,550,50,30);
	//与内总线相连
	Gbuffer.drawLine(320, 210, 350, 210);
	Gbuffer.drawLine(320, 280, 350, 280);
	Gbuffer.drawLine(320, 350, 350, 350);
	Gbuffer.drawLine(320, 420, 350, 420);
	Gbuffer.drawLine(320, 490, 350, 490);
	Gbuffer.drawLine(320, 560, 350, 560);
	Gbuffer.drawLine(350, 220, 370, 220);
	Gbuffer.drawLine(350, 290, 370, 290);
	Gbuffer.drawLine(350, 430, 370, 430);
	Gbuffer.drawLine(350, 500, 370, 500);
	Gbuffer.drawLine(350, 570, 370, 570);
	//MAR与AB相连
	Gbuffer.drawLine(420, 210, 440, 210);
	Gbuffer.drawLine(440, 210, 440, 100);
	//MDR与DB相连
	Gbuffer.drawLine(420, 280, 450, 280);
	Gbuffer.drawLine(450, 280, 450, 120);
	//IR与CB相连
	Gbuffer.drawLine(420, 360, 460, 360);
	Gbuffer.drawLine(460, 360, 460, 140);
	//控制逻辑
	Gbuffer.drawLine(470, 140, 470, 400);
	Gbuffer.fillRect(450,400,40,40);	
	//主存
	Gbuffer.fillRect(480,200,60,30);
	Gbuffer.drawLine(495, 100, 495, 200);
	Gbuffer.drawLine(510, 120, 510, 200);
	Gbuffer.drawLine(525, 140, 525, 200);
	//接口、IO
	Gbuffer.fillRect(570,200,60,30);
	Gbuffer.drawLine(585, 100, 585, 200);
	Gbuffer.drawLine(600, 120, 600, 200);
	Gbuffer.drawLine(615, 140, 615, 200);
	Gbuffer.drawLine(600, 230, 600, 290);
	Gbuffer.fillRect(570,290,60,30);
	//区域
	Gbuffer.drawLine(710, 60, 710, 780);
	//
	//写名字
	Gbuffer.setColor(Color.white);
	Gbuffer.drawString("I/O",590, 310);
	Gbuffer.drawString("接口",590, 220);
	Gbuffer.drawString("主存",500, 220);
	Gbuffer.drawString("控制",458, 418);
	Gbuffer.drawString("逻辑",458, 435);
	Gbuffer.drawString("R0",300, 220);
	Gbuffer.drawString("MAR",380, 220);
	Gbuffer.drawString("R1",300, 290);
	Gbuffer.drawString("MDR",380, 290);
	Gbuffer.drawString("R2",300, 360);
	Gbuffer.drawString("IR",380, 360);
	Gbuffer.drawString("R3",300, 430);
	Gbuffer.drawString("PC",380, 430);
	Gbuffer.drawString("C" ,300, 500);
	Gbuffer.drawString("SP",380, 500);
	Gbuffer.drawString("D" ,300, 570);
	Gbuffer.drawString("PSW",380, 570);
	Gbuffer.drawString("选择器A",60, 410);
	Gbuffer.drawString("选择器B",145, 410);
	Gbuffer.drawString("ALU",120, 310);
	Gbuffer.drawString("移位器",110, 220);		
	Gbuffer.setColor(Color.black);
	Gbuffer.drawString("R0 .  .  .   R3",55, 470);
	Gbuffer.drawString("R0 .  .  .   R3",140, 470);
	Gbuffer.drawString("C  、       D  ",55, 490);
	Gbuffer.drawString("C  、       D  ",140, 490);
	Gbuffer.drawString("PC  、     SP ",55, 510);
	Gbuffer.drawString("PSW 、  MDR ",140, 510);
	Gbuffer.drawString("地址总线", 655, 100);
	Gbuffer.drawString("数据总线", 655, 120);	
	Gbuffer.drawString("控制总线", 655, 140);
	Gbuffer.drawString("选择指令：", 720, 70);
	Gbuffer.drawString("选择指令：", 720, 100);
	Gbuffer.drawString("选择源操作数选址方式：", 720, 130);
	Gbuffer.drawString("选择目的操作数选址方式：", 720, 160);
	Gbuffer.drawString("输入指令为：", 720, 190);
	Gbuffer.fillOval(345,225, 10, 10);
	if(choice==1111){
		System.out.println(next_step);
		switch(next_step){
		case 1:
		{
			M_IR();
			status++;	
			System.out.println(status);
			if(status==11||status==-1) {
				Gbuffer.setColor(getBackground());
				Gbuffer.fillRect(0, 0, WIDTH, HEIGHT);
				status=-1;
			}
			break;
		}		
		case 2:
		{
			PC_1_PC();
			status++;
			if(status==10||status==-1) {
				Gbuffer.setColor(getBackground());
				Gbuffer.fillRect(0, 0, WIDTH, HEIGHT);
				status=-1;
			}
			break;
		}
		}
	}
	g.drawImage(Ibuffer,0,0,this);
}
public void update(Graphics g){
	paint(g);
}
public void M_IR(){
	Gbuffer.setColor(Color.red);
	if(status==0){
		Gbuffer.fillRect(480,200,60,30);
		Gbuffer.setColor(Color.white);
		Gbuffer.drawString("主存",500, 220);
		try {
			Thread.sleep(500);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		repaint();
	}
	else if(status==1){
		Gbuffer.setColor(Color.red);
		Gbuffer.fillOval(520, 190, 10, 10);
		Gbuffer.fillOval(520, 170, 10, 10);
		Gbuffer.fillOval(520, 150, 10, 10);	
		try {
			Thread.sleep(300);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		repaint();
	}
	else if(status==2){
		
		Gbuffer.fillOval(520, 135, 10, 10);
		Gbuffer.fillOval(500, 135, 10, 10);
		Gbuffer.fillOval(480, 135, 10, 10);
		try {
			Thread.sleep(300);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		repaint();
		}
	if(status==3){
		Gbuffer.fillOval(455, 135, 10, 10);
		Gbuffer.fillOval(455, 150, 10, 10);
		Gbuffer.fillOval(455, 170, 10, 10);
		try {
			Thread.sleep(300);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		repaint();
		}
	if(status==4){
		Gbuffer.fillOval(455, 190, 10, 10);
		Gbuffer.fillOval(455, 210, 10, 10);
		Gbuffer.fillOval(455, 230, 10, 10);
		try {
			Thread.sleep(300);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		repaint();
		}
	if(status==5){
		Gbuffer.fillOval(455, 190, 10, 10);
		Gbuffer.fillOval(455, 210, 10, 10);
		Gbuffer.fillOval(455, 230, 10, 10);
		try {
			Thread.sleep(300);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		repaint();
		}
	if(status==6){
		Gbuffer.fillOval(455, 250, 10, 10);
		Gbuffer.fillOval(455, 270, 10, 10);
		Gbuffer.fillOval(455, 290, 10, 10);
		try {
			Thread.sleep(300);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		repaint();
		}
	else if(status==7){
		Gbuffer.fillOval(455, 310, 10, 10);
		Gbuffer.fillOval(455, 330, 10, 10);
		Gbuffer.fillOval(455, 355, 10, 10);
		try {
			Thread.sleep(300);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		repaint();
		}
	else if(status==8){
		Gbuffer.fillOval(440, 355, 10, 10);
		Gbuffer.fillOval(420, 355, 10, 10);
		try {
			Thread.sleep(300);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		repaint();
		}
	else if(status==9){
		Gbuffer.fillOval(440, 355, 10, 10);
		Gbuffer.fillOval(420, 355, 10, 10);
		try {
			Thread.sleep(300);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		repaint();
		}
	else if(status==10){
		Gbuffer.setColor(Color.red);
		Gbuffer.fillRect(370,340,50,30);
		Gbuffer.setColor(Color.white);
		Gbuffer.drawString("IR",380, 360);
		try {
			Thread.sleep(500);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		repaint();
		}
}
void PC_1_PC(){
	Gbuffer.setColor(Color.red);
	if(status==0){
		Gbuffer.fillRect(370,410,50,30);
		Gbuffer.setColor(Color.white);
		Gbuffer.drawString("PC",380, 430);
		try {
			Thread.sleep(500);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		repaint();
	}
	if(status==0){
		Gbuffer.fillOval(370, 410, 10, 10);
		Gbuffer.fillOval(520, 170, 10, 10);
		Gbuffer.fillOval(520, 150, 10, 10);
		try {
			Thread.sleep(500);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		repaint();
	}	
	if(status==0){
		Gbuffer.fillOval(520, 135, 10, 10);
		Gbuffer.fillOval(500, 135, 10, 10);
		Gbuffer.fillOval(480, 135, 10, 10);
		try {
			Thread.sleep(500);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		repaint();
	}		
		
		Gbuffer.fillOval(455, 135, 10, 10);
		Gbuffer.fillOval(455, 150, 10, 10);
		Gbuffer.fillOval(455, 170, 10, 10);
		Gbuffer.fillOval(455, 190, 10, 10);
		Gbuffer.fillOval(455, 210, 10, 10);
		Gbuffer.fillOval(455, 230, 10, 10);
		Gbuffer.fillOval(455, 250, 10, 10);
		Gbuffer.fillOval(455, 270, 10, 10);
		Gbuffer.fillOval(455, 290, 10, 10);
		Gbuffer.fillOval(455, 310, 10, 10);
		Gbuffer.fillOval(455, 330, 10, 10);
		Gbuffer.fillOval(455, 355, 10, 10);
		Gbuffer.fillOval(440, 355, 10, 10);
		Gbuffer.fillOval(420, 355, 10, 10);
		repaint();
		status++;
	}


public static void main(String []argc){
	new CPU8086();
}



}

